<template>
    <basic-container>
        <avue-crud :option="option" :data="data" ref="crud" v-model="form" :table-loading="loading"
                   :permission="permissionList"
                   :page="page" @refresh-change="refreshChange" @search-change="searchChange"
                   @search-reset="searchReset"
                   @current-change="currentChange" @size-change="sizeChange" @on-load="onLoad">
            <!-- 自定义添加搜索条件  按日期搜索  -->
            <template slot="search">
                <el-col :md="12" :xs="12" style="height: 52px;">
                    <el-form-item label="有效期">
                        <el-date-picker text="有效期" v-model="acTime" type="datetimerange" range-separator="至" size="mini"
                                        start-placeholder="活动开始日期" :default-time="['12:00:00', '22:00:00']"
                                        end-placeholder="活动结束日期" align="right"
                                        format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss">
                        </el-date-picker>
                    </el-form-item>
                </el-col>
            </template>
            <template slot-scope="{ row }" slot="organizationIds">
                <el-button size="mini" type="text" style="color: #606266;" @click="handleRowClick(row)">点击查看</el-button>
            </template>
            <template slot="menuLeft">
                <el-button @click="addNew()" icon="el-icon-plus" size="mini" type="primary"
                           v-has="'/mall-cloud-activity/activity/saveOrUpdate'">新增活动
                </el-button>
            </template>
            <template slot-scope="scope" slot="menu">
                <el-button @click="editAct(scope.row)"
                           v-if="scope.row.acStage!=4&&scope.row.acStage!=-1&&scope.row.type==2" size="mini" type="text"
                           v-has="'/mall-cloud-activity/activity/saveOrUpdate'">编辑
                </el-button>
                <el-button @click="showAct(scope.row)" size="mini" type="text">查看</el-button>
                <el-button @click="auditAct(scope.row)" v-if="scope.row.acStatus==3&&scope.row.type==1" size="mini"
                           type="text" v-has="'/mall-cloud-activity/activity/platformAuditAct'">审核
                </el-button>
                <el-button @click="applyList(scope.row)" size="mini" type="text"
                           v-has="'/mall-cloud-activity/activityGoods/list'">申请列表
                </el-button>
                <el-button @click="cancelActivity(scope.row.id)"
                           v-if="scope.row.acStage!=4&&scope.row.acStage!=-1 && scope.row.acStage!=-2" size="mini"
                           type="text" v-has="'/mall-cloud-activity/activity/cancel'">取消
                </el-button>
                <!-- <el-button @click="activityLink(scope.row)" size="mini" type="text">活动链接</el-button> -->
                <!--				<el-button @click="statisticsBut(scope.row)" size="mini" type="text">统计信息</el-button>-->
            </template>
        </avue-crud>
        <!-- 新增和编辑-->
        <el-drawer :wrapperClosable="false" :visible.sync="drawerNew" :with-header="false" size="70%">
            <div class="demo-drawer__header">
                <div class="drawerHeader">
                    <strong>{{deawerNewTitle}}</strong>
                </div>
            </div>
            <div class="demo-drawer__content">
                <avue-form ref="form" v-model="obj" :option="newOption" @submit="submit">
                    <template slot-scope="scope" slot="preheatTime">
                        <div class="upload">
                            <div class="upload">
                                <el-date-picker v-model="obj.preheatTime" :disabled="isView || deawerNewTitle=='编辑活动'"
                                                format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss"
                                                type="datetime"
                                                placeholder="选择活动预热时间" @change="checkPreheatTime" align="right"
                                                :picker-options="pickerOption"></el-date-picker>
                            </div>
                        </div>
                    </template>
                    <template slot-scope="scope" slot="acTime">
                        <div class="upload">
                            <el-date-picker v-model="obj.acTime" :disabled="isView || +new Date()>+new Date(obj.acTime[0])"
                                            type="datetimerange" :picker-options="pickerOptions" range-separator="至"
                                            start-placeholder="活动开始日期" end-placeholder="活动结束日期" align="right"
                                            format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss">
                            </el-date-picker>
                        </div>
                    </template>
                    <template slot-scope="scope" slot="acPcAccUrl">
                        <div class="upload">
                            <el-input style="margin-right: 0.2rem;" :disabled="isView" @focus="uploadbtn(1)"
                                      v-model="obj.acPcAccUrl" :clearable='true' placeholder="最佳尺寸:1280px*500px"
                                      :readonly="true"/>
                            <el-image v-if="obj.acPcAccUrl" @click="uploadbtn" fit="contain" :src="obj.acPcAccUrl"
                                      style="margin-right: 0.2rem;width: 50px; height: 50px">
                            </el-image>
                            <el-button size="mini" type="primary" @click="uploadbtn(1)">上传图片</el-button>
                            <p class="tsmsg">最多可上传1张照片</p>
                        </div>
                    </template>
                    <template slot-scope="scope" slot="acH5AccUrl">
                        <div class="upload">
                            <el-input style="margin-right: 0.2rem;" :disabled="isView" @focus="uploadbtn(2)"
                                      v-model="obj.acH5AccUrl" :readonly="true" placeholder="最佳比例2：1"/>
                            <el-image v-if="obj.acH5AccUrl" @click="uploadbtn" fit="contain" :src="obj.acH5AccUrl"
                                      style="margin-right: 0.2rem;width: 50px; height: 50px;margin: 0 0.2rem;">
                            </el-image>
                            <el-button size="mini" type="primary" @click="uploadbtn(2)">上传图片</el-button>
                            <p class="tsmsg">最多可上传1张照片</p>
                        </div>
                    </template>
                    <template slot-scope="scope" slot="appPcAccUrl">
                        <div class="upload">
                            <el-input style="margin-right: 0.2rem;" :disabled="isView" v-model="obj.appPcAccUrl"
                                      :readonly="true"/>
                            <el-image v-if="obj.appPcAccUrl" @click="uploadbtn" fit="contain" :src="obj.appPcAccUrl"
                                      style="margin-right: 0.2rem;margin: 0 0.2rem;width: 50px; height: 50px">
                            </el-image>
                            <el-button size="mini" type="primary" @click="uploadbtn(3)">上传图片</el-button>
                            <p class="tsmsg">最多可上传1张照片</p>
                        </div>
                    </template>
                    <template slot-scope="scope" slot="menuForm">
                        <el-button v-if="!isView" @click="closeDrawer">取消</el-button>
                        <el-button v-else @click="closeDrawer">关闭</el-button>
                    </template>
                </avue-form>
            </div>
        </el-drawer>
        <!--查看-->
        <el-drawer :wrapperClosable="false" :visible.sync="drawerShow" :with-header="false" size="60%">
            <div class="demo-drawer__header">
                <div class="drawerHeader">
                    <strong>查看活动</strong>
                </div>
            </div>
            <div class="demo-drawer__content">
                <avue-form ref="showForm" v-model="showObj" :option="showOption">
                    <template slot-scope="scope" slot="acContent">
                        <el-input disabled :value="showObj.acContent || '无活动说明'"></el-input>
                    </template>
                    <template slot-scope="scope" slot="preheatTime">
                        <div class="upload">
                            <div class="upload">
                                <el-date-picker v-model="showObj.preheatTime" :disabled="true"
                                                format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss"
                                                type="datetime"
                                                placeholder="选择活动预热时间" align="right"
                                                :picker-options="pickerOption"></el-date-picker>
                            </div>
                        </div>
                    </template>
                    <template slot-scope="scope" slot="organizationIds">
                        <el-select v-model="showObj.organizationIds" size="mini" placeholder="请选择" multiple
                                   collapse-tags>
                            <el-option :value="showObj.organizationIds" style="height: auto">
                                <el-tree :data="organizationIdsOption" :default-expanded-keys="[]" node-key="id"
                                         accordion ref="signTree" highlight-current :props="props1"></el-tree>
                            </el-option>
                        </el-select>
                    </template>
                    <template slot-scope="scope" slot="gcIds">
                        <el-select v-model="showObj.goodsClassIdsName" size="mini" placeholder="请选择" multiple
                                   collapse-tags>
                            <el-option :value="showObj.goodsClassIdsName" style="height: auto">
                                <el-tree
                                        :data="goodsClassIdsOptions"
                                        :default-expanded-keys="[]"
                                        node-key="id"
                                        accordion
                                        ref="goodsClassTree"
                                        highlight-current
                                        :props="propsClass"
                                ></el-tree>
                            </el-option>
                        </el-select>
                    </template>
                    <template slot-scope="scope" slot="acTime">
                        <div class="upload">
                            <el-date-picker :disabled="true" v-model="showObj.acTime" type="datetimerange"
                                            :picker-options="pickerOptions" range-separator="至"
                                            start-placeholder="活动开始日期" end-placeholder="活动结束日期" align="right"
                                            format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss">
                            </el-date-picker>
                        </div>
                    </template>
                    <template slot-scope="scope" slot="acPcAccUrl">
                        <div class="upload">
                            <el-input style="margin-right: 0.2rem;" v-model="showObj.acPcAccUrl" :clearable='true'
                                      placeholder="最佳尺寸:1280px*500px"
                                      :readonly="true"/>
                            <el-image v-if="showObj.acPcAccUrl" :disabled="true" @click="uploadbtn" fit="contain"
                                      :src="showObj.acPcAccUrl" style="margin-right: 0.2rem;width: 50px; height: 50px">
                            </el-image>
                        </div>
                    </template>
                    <template slot-scope="scope" slot="acH5AccUrl">
                        <div class="upload">
                            <el-input style="margin-right: 0.2rem;" :disabled="true" @focus="uploadbtn(2)"
                                      v-model="showObj.acH5AccUrl" :readonly="true" placeholder="最佳比例2：1"/>
                            <el-image v-if="showObj.acH5AccUrl" fit="contain" :src="showObj.acH5AccUrl"
                                      style="margin-right: 0.2rem;width: 50px; height: 50px;margin: 0 0.2rem;">
                            </el-image>
                        </div>
                    </template>
                    <template slot-scope="scope" slot="appPcAccUrl">
                        <div class="upload">
                            <el-input style="margin-right: 0.2rem;" :disabled="true" v-model="showObj.appPcAccUrl"
                                      :readonly="true"/>
                            <el-image v-if="showObj.appPcAccUrl" fit="contain" :src="showObj.appPcAccUrl"
                                      style="margin-right: 0.2rem;margin: 0 0.2rem;width: 50px; height: 50px">
                            </el-image>
                        </div>
                    </template>
                    <template slot-scope="scope" slot="menuForm">
                        <el-button @click="closeShowDrawer">关闭</el-button>
                    </template>
                </avue-form>
            </div>
        </el-drawer>
        <!-- 申请列表 -->
        <el-drawer :wrapperClosable="true" :visible.sync="drawerActivity" :with-header="false" size="60%">
            <div class="demo-drawer__header">
                <div class="drawerHeader">
                    <strong>申请列表</strong>
                </div>
            </div>
            <div class="demo-drawer__content">
                <avue-crud ref="goodsCrud" :data="goodsList" :option="optionGoods" v-model="objGoods"
                           :table-loading="goodsloading"
                           :permission="permissionList" :page="goodsPage" @selection-change="selectionChange"
                           @refresh-change="refreshGoodsChange"
                           @search-change="searchGoodsChange" @search-reset="searchGoodsReset"
                           @current-change="currentGoodsChange"
                           @size-change="sizeGoodsChange" @on-load="onGoodsLoad">
                    <template slot-scope="{row}" slot="goodsMainPhotoUrl">
                        <img :src="row.goodsMainPhotoUrl" style="width:50px;height:50px;"/>
                    </template>
                    <template slot-scope="{row}" slot="price">
                        <span>{{row.goodsPriceBean.price}}</span>
                    </template>
                    <template slot-scope="scope" slot="menu">
                        <el-button @click="goodsDetail(scope.row.goodsId)" size="mini" type="text">详情</el-button>
                        <el-button v-if="scope.row.agStatus==0 ||scope.row.agStatus==1" @click="refuse(scope.row.id)"
                                   size="mini" type="text"
                                   v-has="'/mall-cloud-activity/activityGoods/joinActivityAudit'">拒绝
                        </el-button>
                        <el-button v-if="scope.row.agStatus==0 ||scope.row.agStatus==-1" @click="pass(scope.row.id)"
                                   size="mini" type="text"
                                   v-has="'/mall-cloud-activity/activityGoods/joinActivityAudit'">通过
                        </el-button>
                        <el-button @click="viewStore(scope.row.storeId)" size="mini" type="text">查看店铺</el-button>
                    </template>
                </avue-crud>
                <div style="padding: 10px 30px;">
                    <el-button type="primary" @click="refuseAll()"
                               v-has="'/mall-cloud-activity/activityGoods/joinActivityAudit'">全部拒绝
                    </el-button>
                    <el-button type="primary" @click="passAll()"
                               v-has="'/mall-cloud-activity/activityGoods/joinActivityAudit'">全部通过
                    </el-button>
                </div>
            </div>
        </el-drawer>
        <!-- 查看活动路径-->
        <el-dialog title="活动路径" :visible.sync="dialogLink" width="30%">
            <div class="diaLink">
                <!-- <strong style="color: #000;">PC端活动路径：</strong>
                <p>{{pcLink}}</p> -->
                <strong style="color: #000;">H5端活动路径：</strong>
                <p>{{h5Link}}</p>
            </div>
            <span slot="footer" class="dialog-footer">
				<el-button type="primary" @click="dialogLink = false">关 闭</el-button>
			</span>
        </el-dialog>
        <selFile ref="selFile" selectType="radio" @callback="selFileCallBack" albumCode="pic_root" dialogTitle="选择图片1"
                 selMaxWidth="500px" selMaxHeight="1280px">
        </selFile>
        <el-drawer title="商品详情" size="70%" :withHeader=false :visible.sync="dialogTableVisible" width="70%">
            <add-goods v-if="dialogTableVisible" :disadledSpec="disadledSpec" :goodsId="goodsId" :isPublish="isPublish"
                       :isCheck="isCheck"
                       :isRedact="isRedact"></add-goods>
        </el-drawer>
        <store-detail @closeDrawer="closeDrawers" :isActivity="true" :storeId="storeId" :isView="isView"
                      :dialogFormVisible="dialogFormVisible"></store-detail>
        <!--		店铺活动审核对话框-->
        <el-dialog
                width="60%"
                :visible.sync="auditDialogFormVisible"
                :title="auditTitle"
                @close="closeDialog"
                append-to-body
                :close-on-click-modal="false"
        >
            <avue-form ref="formAudit" v-model="objAudit" :option="optionAudit" @submit="submitAudit">
                <template slot-scope="scope" slot="acTitle">
                    <div class="auditColor" v-if="objAudit.acTitle">{{objAudit.acTitle}}</div>
                </template>
                <template slot-scope="scope" slot="acH5AccUrl">
                    <el-image
                            style="width: 100px; height: 100px"
                            fit="contain"
                            :src="objAudit.acH5AccUrl"
                            :preview-src-list="[objAudit.acH5AccUrl]">
                    </el-image>
                </template>
                <template slot-scope="scope" slot="acFullcuts">
                    <div class="auditColor" v-if="objAudit.acSessions.length>0">
                        <p v-for="item of objAudit.acSessions" :key="item.id">{{item.beginTime}} - {{item.endTime}}</p>
                    </div>
                </template>
                <template slot-scope="scope" slot="acContent">
                    <div class="auditColor" v-if="objAudit.acContent">{{objAudit.acContent}}</div>
                </template>
            </avue-form>
        </el-dialog>
        <!--		点击查看区域对话框-->
        <el-dialog title="区域" @close="closeAreas" :visible.sync="currentGoodsVis" width="40%" center>
            <span style="padding: 20px;color: #000;">{{ currentGoodsName }}</span>
            <div style="padding: 20px;max-height: 300px;overflow: scroll;line-height: 30px;">
                <el-tree :data="currentAreas" :default-expanded-keys="defaultKeys" :default-checked-keys="defaultKeys"
                         show-checkbox node-key="id" accordion ref="goodsClassTree" highlight-current
                         :props="propsClassOrgination"></el-tree>
            </div>
        </el-dialog>
    </basic-container>
</template>

<script>

    import storeDetail from '@/components/store/storeDetail.vue'
    import selFile from '@/components/file/selFile'
    import {getListTree, getClassTree} from '@/api/base/store/store';
    import {
        saveOrUpdate,
        getActList,
        joinActivityAudit,
        testAcRebate,
        getList,
        cancel,
        platformAuditAct
    } from '@/api/base/activity/discountAct'
    import addGoods from '@/views/base/goods/seller/addGoods';
    import {getOrganizationTreeNodeByIds} from '@/api/base/goods/goods';
    import {getGoodsClassTreeNodesByIds, getMapAllGoodsClass} from "@/api/base/store/store";
    import {getOrganizationMapByLevel} from '@/api/base/goods/addGoods';
    import {
        mapGetters
    } from "vuex";

    var Dict = JSON.parse(localStorage.getItem("mall-dictionary")).content;
    var baseUrl = 'https://testapimall.sunac.com.cn/'
    var VAILD = [{
        label: '不包邮',
        value: 0
    }, {
        label: '包邮',
        value: 1
    },]
    var YES_OR_NO = [{
        label: '关闭',
        value: 0
    }, {
        label: '开启',
        value: 1
    }]
    var YES_OR_NO1 = [{
        label: '关闭',
        value: 0
    }, {
        label: '开启',
        value: 1
    }, {
        label: '平台关闭',
        value: 2
    }, {
        label: '待平台审核',
        value: 3
    },]
    var OPEN_OR_NOT = [{
        label: '拒绝',
        value: 0
    }, {
        label: '同意',
        value: 1
    },]
    export default {
        data() {
            return {
                defaultKeys: [],
                currentAreas: '',
                currentGoodsVis: false,
                currentGoodsName: '',
                propsClassOrgination: {
                    label: 'name',
                    id: 'id',
                    children: 'childrenNodes',
                },
                storeId: "",
                dialogFormVisible: false,
                pickerOptions: {
                    disabledDate(time) {
                        return time.getTime() + 3600 * 1000 * 24 * 1 < Date.now();
                    },
                    shortcuts: [{
                        text: '未来一周',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            end.setTime(start.getTime() + 3600 * 1000 * 24 * 7);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '未来一个月',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            end.setTime(start.getTime() + 3600 * 1000 * 24 * 30);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '未来三个月',
                        onClick(picker) {
                            const end = new Date();
                            const start = new Date();
                            end.setTime(start.getTime() + 3600 * 1000 * 24 * 90);
                            picker.$emit('pick', [start, end]);
                        }
                    }]
                },
                pickerOption: {
                    disabledDate(time) {
                        return time.getTime() + 3600 * 1000 * 24 * 1 < Date.now();
                    },
                    shortcuts: [{
                        text: '今天',
                        onClick(picker) {
                            picker.$emit('pick', new Date());
                        }
                    }, {
                        text: '明天',
                        onClick(picker) {
                            const date = new Date();
                            date.setTime(date.getTime() + 3600 * 1000 * 24);
                            picker.$emit('pick', date);
                        }
                    }, {
                        text: '一周后',
                        onClick(picker) {
                            const date = new Date();
                            date.setTime(date.getTime() + 3600 * 1000 * 24 * 7);
                            picker.$emit('pick', date);
                        }
                    }]
                },
                form: {},
                pcLink: '',
                h5Link: '',
                query: {
                    acType: 3
                },
                dialogTableVisible: false, //商品详情
                isPublish: false,
                isCheck: false,
                isRedact: false,
                disadledSpec: false,
                goodsId: "",
                drawerNew: false,
                isView: false,
                dialogLink: false,
                deawerNewTitle: '新增活动',
                drawerActivity: false,
                obj: {},
                auditDialogFormVisible: false,
                auditTitle: "活动审核",
                objAudit: {},
                optionAudit: {
                    labelWidth: 200,
                    emptyBtn: false,
                    column: [{
                        label: "活动名称",
                        prop: "acTitle",
                        span: 24,
                        formslot: true,
                    },
                        {
                            label: "活动预热时间",
                            prop: "preheatTime",
                            span: 24,
                        },
                        {
                            label: "活动场次",
                            prop: "acFullcuts",
                            span: 24,
                            formslot: true,
                        },
                        {
                            label: "活动横幅",
                            prop: "acH5AccUrl",
                            span: 24,
                            formslot: true,
                        },
                        {
                            label: "活动描述",
                            prop: "acContent",
                            span: 24,
                            formslot: true,
                        },
                        {
                            label: "审核",
                            prop: "acStatus",
                            span: 16,
                            type: "radio",
                            row: true,
                            dicData: OPEN_OR_NOT,
                            valueDefault: 1,

                        },
                    ]
                },
                //申请列表商品
                goodsList: [],
                imageType: 1,
                data: [],
                loading: true,
                goodsloading: true,
                actGoodsLoading: true,
                rolesTree: [],
                rolesKeys: [],
                acTime: '',
                box: false,
                page: {
                    pageSize: 10,
                    currentPage: 1,
                    total: 0
                },
                goodsPage: {
                    pageSize: 10,
                    currentPage: 1,
                    total: 0
                },
                idList: [],
                goodsQuery: {},
                actGoodsQuery: {
                    acId: ''
                },
                objGoods: {},
                //店铺商品列表
                optionGoods: {
                    searchMenuSpan: 8,
                    header: false,
                    selection: true,
                    menu: true,
                    editBtn: false,
					border: true,
                    delBtn: false,
                    search: true,
                    column: [{
                        label: "商品名称",
                        prop: "goodsName",
                        labelWidth: 300,
                        search: true,
                    },
                        {
                            label: "申请状态",
                            type: 'select',
                            prop: "agStatus",
                            dicData: Dict.STORE_BRAND_STATUS,
                            search: true,
                        },
                        {
                            label: "店铺名称",
                            prop: "storeName",

                        }, {
                            label: "商城售价",
                            prop: "price",
                            slot: true,
                        }, {
                            label: "签约区域",
                            prop: "signingAreaName",

                        }, {
                            label: "商品评分",
                            prop: "goodsAvgScore",

                        },
                    ]
                },
                newOption: {
                    // size: 'mini',
                    submitText: '完成',
                    emptyBtn: false,
                    submitBtn: true,
                    labelWidth: '120',
                    column: [{
                        label: "活动名称",
                        prop: "acTitle",
                        tip: '活动名称不超过10个字符',
                        span: 20,
                        maxlength: 10,
                        disabled: true,
                        row: true,
                        rules: [{
                            required: true,
                            message: "请输入活动名称",
                            trigger: "blur"
                        }],
                    }, {
                        label: '活动预热时间',
                        prop: 'preheatTime',
                        type: 'datetime',
                        formslot: true,
                        disabled: true,
                        row: true,
                        span: 20,
                        rules: [{
                            required: true,
                            message: '请选择活动预热时间',
                            trigger: 'blur'
                        }]
                    },
                        {
                            label: '秒杀活动',
                            type: 'dynamic',
                            prop: 'acTime',
                            disabled: true,
                            span: 20,
                            tip: '注意：活动时间都是整点，开始时间不能重复',
                            rules: [{
                                required: true,
                                message: '请添加秒杀活动时间',
                                trigger: 'blur'
                            }],
                            children: {
                                align: 'center',
                                headerAlign: 'center',
                                rowAdd: (done) => {
                                    done({
                                        input: '默认值'
                                    });
                                    this.getTrueArray();
                                },
                                column: [{
                                    type: 'datetimerange',
                                    label: '秒杀时间范围',
                                    span: 20,
                                    format: 'yyyy-MM-dd HH:mm:ss',
                                    valueFormat: 'yyyy-MM-dd HH',
                                    prop: 'acTime',
                                    readonly: true,
                                    startPlaceholder: '开始时间( 整点时间, 不能重复)',
                                    endPlaceholder: '结束时间(整点时间)',
                                    required: true,
                                    rules: [{
                                        required: true,
                                        message: '至少填写一个秒杀时间范围'
                                    }],
                                    blur: () => {
                                        setTimeout(() => {
                                            this.getTime();
                                        }, 10)
                                    },
                                    pickerOptions: {
                                        disabledDate(time) {
                                            return time.getTime() + 3600 * 1000 * 24 * 1 < Date.now();
                                        },
                                        shortcuts: [{
                                            text: '未来一周',
                                            onClick(picker) {
                                                console.log(picker);
                                                const end = new Date();
                                                const start = new Date();
                                                end.setTime(start.getTime() + 3600 * 1000 * 24 * 7);
                                                picker.$emit('pick', [start, end]);
                                            }
                                        }
                                            // {
                                            // 	text: '未来一个月',
                                            // 	onClick(picker) {
                                            // 		const end = new Date();
                                            // 		const start = new Date();
                                            // 		end.setTime(start.getTime() + 3600 * 1000 * 24 * 30);
                                            // 		picker.$emit('pick', [start, end]);
                                            // 	}
                                            // }, {
                                            // 	text: '未来三个月',
                                            // 	onClick(picker) {
                                            // 		const end = new Date();
                                            // 		const start = new Date();
                                            // 		end.setTime(start.getTime() + 3600 * 1000 * 24 * 90);
                                            // 		picker.$emit('pick', [start, end]);
                                            // 	}
                                            // },
                                        ]
                                    }
                                }]
                            }
                        },
                        // {
                        // 	label: "报名截止时间",
                        // 	prop: "acApplyEndTime",
                        // 	type: "datetime",
                        // 	formslot: true,
                        // 	span: 12,
                        // 	row: true,
                        // 	rules: [{
                        // 		required: true,
                        // 		message: "请选择报名截止时间",
                        // 		trigger: "blur"
                        // 	}],
                        // },
                        // {
                        // 	label: "pc活动横幅",
                        // 	prop: "acPcAccUrl",
                        // 	tip: '最佳尺寸:1280px*500px',
                        // 	formslot: true,
                        // 	span: 22,
                        // 	row: true,
                        // 	rules: [{
                        // 		required: true,
                        // 		message: "请选择pc活动横幅",
                        // 		trigger: 'change'
                        // 	}],
                        // },
                        {
                            label: "H5端活动横幅",
                            prop: "acH5AccUrl",
                            tip: '最佳比例:2：1',
                            formslot: true,
                            disabled: true,
                            row: true,
                            span: 22,
                            rules: [{
                                required: true,
                                message: "请选择H5端活动横幅",
                                trigger: 'change'
                            }],
                        },
                        {
                            label: "活动范围",
                            prop: "organizationIds",
                            type: "tree",
                            dicData: [],
                            multiple: true,
                            defaultExpandAll: false,
                            disabled: true,
                            props: {
                                label: 'name',
                                value: 'id',
                                children: "childrenNodes"
                            },
                            span: 16,
                        },
                        {
                            label: "分类",
                            prop: "gcIds",
                            type: "tree",
                            dicData: [],
                            multiple: true,
                            defaultExpandAll: false,
                            disabled: true,
                            props: {
                                label: 'className',
                                value: 'id',
                                children: "childrenNodes"
                            },
                            span: 16,
                            rules: [{
                                required: true,
                                message: "请选择分类",
                            }],
                        },
                        // {
                        // 	label: "APP导航图标",
                        // 	prop: "appPcAccUrl",
                        // 	formslot: true,
                        // 	tip: '最佳尺寸:1:1',
                        // 	span: 16,
                        // 	row: true,
                        // 	rules: [{
                        // 		required: true,
                        // 		message: "请选择APP导航图标",
                        // 	}],
                        // },
                        {
                            label: "是否开启",
                            prop: "acStatus",
                            span: 16,
                            type: "radio",
                            disabled: true,
                            row: true,
                            dicData: YES_OR_NO,
                            valueDefault: 1,
                        },
                        {
                            label: "邮费类型",
                            prop: "acFreeShipping",
                            span: 16,
                            type: "radio",
                            dicData: VAILD,
                            disabled: true,
                            row: true,
                            rules: [{
                                required: true,
                                message: "请选择邮费类型",
                                trigger: "blur"
                            }],
                            valueDefault: 0,
                        },
                        {
                            label: "活动说明",
                            prop: "acContent",
                            tip: '活动说明不超过50个字符',
                            type: 'textarea',
                            minRows: 2,
                            disabled: true,
                            span: 20,
                            maxlength: 50,
                            // rules: [{
                            //     required: true,
                            //     message: '请输入活动说明'
                            // }]
                        },
                    ]
                },
                drawerShow: false,
                propsClass: {
                    label: 'className',
                    id: 'id',
                    children: 'childrenNodes'
                },
                props1: {
                    label: 'name',
                    id: 'id',
                    children: 'childrenNodes',
                },
                showObj: {},
                showOption: {
                    // size: 'mini',
                    submitText: '完成',
                    emptyBtn: false,
                    submitBtn: false,
                    labelWidth: '120',
                    column: [{
                        label: "活动名称",
                        prop: "acTitle",
                        tip: '活动名称不超过10个字符',
                        span: 20,
                        maxlength: 10,
                        disabled: true,
                        row: true,
                        rules: [{
                            required: true,
                            message: "请输入活动名称",
                            trigger: "blur"
                        }],
                    }, {
                        label: '活动预热时间',
                        prop: 'preheatTime',
                        type: 'datetime',
                        formslot: true,
                        disabled: true,
                        row: true,
                        span: 20,
                        rules: [{
                            required: true,
                            message: '请选择活动预热时间',
                            trigger: 'blur'
                        }]
                    },
                        {
                            label: '秒杀活动',
                            type: 'dynamic',
                            prop: 'acTime',
                            disabled: true,
                            span: 20,
                            tip: '注意：活动时间都是整点，开始时间不能重复',
                            rules: [{
                                required: true,
                                message: '请添加秒杀活动时间',
                                trigger: 'blur'
                            }],
                            children: {
                                align: 'center',
                                headerAlign: 'center',
                                rowAdd: (done) => {
                                    done({
                                        input: '默认值'
                                    });
                                    this.getTrueArray();
                                },
                                column: [{
                                    type: 'datetimerange',
                                    label: '秒杀时间范围',
                                    span: 20,
                                    format: 'yyyy-MM-dd HH:mm:ss',
                                    valueFormat: 'yyyy-MM-dd HH',
                                    prop: 'acTime',
                                    readonly: true,
                                    startPlaceholder: '开始时间( 整点时间, 不能重复)',
                                    endPlaceholder: '结束时间(整点时间)',
                                    required: true,
                                    rules: [{
                                        required: true,
                                        message: '至少填写一个秒杀时间范围'
                                    }],
                                    blur: () => {
                                        setTimeout(() => {
                                            this.getTime();
                                        }, 10)
                                    },
                                    pickerOptions: {
                                        disabledDate(time) {
                                            return time.getTime() + 3600 * 1000 * 24 * 1 < Date.now();
                                        },
                                        shortcuts: [{
                                            text: '未来一周',
                                            onClick(picker) {
                                                console.log(picker);
                                                const end = new Date();
                                                const start = new Date();
                                                end.setTime(start.getTime() + 3600 * 1000 * 24 * 7);
                                                picker.$emit('pick', [start, end]);
                                            }
                                        }
                                            // {
                                            // 	text: '未来一个月',
                                            // 	onClick(picker) {
                                            // 		const end = new Date();
                                            // 		const start = new Date();
                                            // 		end.setTime(start.getTime() + 3600 * 1000 * 24 * 30);
                                            // 		picker.$emit('pick', [start, end]);
                                            // 	}
                                            // }, {
                                            // 	text: '未来三个月',
                                            // 	onClick(picker) {
                                            // 		const end = new Date();
                                            // 		const start = new Date();
                                            // 		end.setTime(start.getTime() + 3600 * 1000 * 24 * 90);
                                            // 		picker.$emit('pick', [start, end]);
                                            // 	}
                                            // },
                                        ]
                                    }
                                }]
                            }
                        },
                        // {
                        // 	label: "报名截止时间",
                        // 	prop: "acApplyEndTime",
                        // 	type: "datetime",
                        // 	formslot: true,
                        // 	span: 12,
                        // 	row: true,
                        // 	rules: [{
                        // 		required: true,
                        // 		message: "请选择报名截止时间",
                        // 		trigger: "blur"
                        // 	}],
                        // },
                        // {
                        // 	label: "pc活动横幅",
                        // 	prop: "acPcAccUrl",
                        // 	tip: '最佳尺寸:1280px*500px',
                        // 	formslot: true,
                        // 	span: 22,
                        // 	row: true,
                        // 	rules: [{
                        // 		required: true,
                        // 		message: "请选择pc活动横幅",
                        // 		trigger: 'change'
                        // 	}],
                        // },
                        {
                            label: "H5端活动横幅",
                            prop: "acH5AccUrl",
                            tip: '最佳比例:2：1',
                            formslot: true,
                            disabled: true,
                            row: true,
                            span: 22,
                            rules: [{
                                required: true,
                                message: "请选择H5端活动横幅",
                                trigger: 'change'
                            }],
                        },
                        {
                            label: "活动范围",
                            prop: "organizationIds",
                            type: "tree",
                            dicData: [],
                            formslot: true,
                            multiple: true,
                            defaultExpandAll: false,
                            disabled: true,
                            props: {
                                label: 'name',
                                value: 'id',
                                children: "childrenNodes"
                            },
                            span: 16,
                        },
                        {
                            label: "分类",
                            prop: "gcIds",
                            type: "tree",
                            dicData: [],
                            formslot: true,
                            multiple: true,
                            defaultExpandAll: false,
                            disabled: true,
                            props: {
                                label: 'className',
                                value: 'id',
                                children: "childrenNodes"
                            },
                            span: 16,
                            rules: [{
                                required: true,
                                message: "请选择分类",
                            }],
                        },
                        // {
                        // 	label: "APP导航图标",
                        // 	prop: "appPcAccUrl",
                        // 	formslot: true,
                        // 	tip: '最佳尺寸:1:1',
                        // 	span: 16,
                        // 	row: true,
                        // 	rules: [{
                        // 		required: true,
                        // 		message: "请选择APP导航图标",
                        // 	}],
                        // },
                        {
                            label: "是否开启",
                            prop: "acStatus",
                            span: 16,
                            type: "radio",
                            disabled: true,
                            row: true,
                            dicData: YES_OR_NO1,
                            valueDefault: 1,
                        },
                        {
                            label: "邮费类型",
                            prop: "acFreeShipping",
                            span: 16,
                            type: "radio",
                            dicData: VAILD,
                            disabled: true,
                            row: true,
                            rules: [{
                                required: true,
                                message: "请选择邮费类型",
                                trigger: "blur"
                            }],
                            valueDefault: 0,
                        },
                        {
                            label: "活动说明",
                            prop: "acContent",
                            formslot: true,
                            tip: '活动说明不超过50个字符',
                            type: 'textarea',
                            minRows: 2,
                            disabled: true,
                            span: 20,
                            maxlength: 50,
                            // rules: [{
                            //     required: true,
                            //     message: '请输入活动说明'
                            // }]
                        },
                    ]
                },
                //所有活动
                option: {
                    size: 'mini',
                    excelBtn: false,
                    addBtn: false,
                    delBtn: false,
                    editBtn: false,
                    viewBtn: false,
                    border: true,
                    "align": "center",
                    search: true,
                    rowKey: 'id',
                    columnBtn: false,
                    menuWidth: 270,
                    column: [{
                        label: "活动标题",
                        prop: "acTitle",
                        width: 210,
                        align: 'left',
                        fixed: true,
                        search: true,
                    }, {
                        label: '区域',
                        prop: 'organizationIds',
                        value: 'organizationIds',
                        searchSpan: 6,
                        search: true,
                        slot: true,
                        multiple: true,
                        defaultExpandAll: false,
                        dicUrl: '/base/organization/listTree',
                        type: 'tree',
                        props: {
                            label: 'name',
                            value: 'id',
                            children: 'childrenNodes'
                        },
                    }, {
                        label: "活动所属",
                        prop: "type",
                        type: 'select',
                        dicData: Dict.STORE_OR_PLATFORM_TYPE_ENUM,
                        search: true,
                    },
                        {
                            label: "创建时间",
                            prop: "addTime",
                            width: 150,
                        }, {
                            label: "创建人",
                            prop: "createUserName",
                            width: 150,
                        },
                        {
                            label: "活动报名截止时间",
                            prop: "acApplyEndTime",
                            width: 145,
                        }, {
                            label: "开始时间",
                            prop: "acBeginTime",
                            width: 145,
                        }, {
                            label: "结束时间",
                            prop: "acEndTime",
                            width: 145,
                        }, {
                            label: "邮费类型",
                            prop: "acFreeShipping",
                            width: 70,
                            dicData: VAILD,
                            type: 'select',
                        }, {
                            label: "是否开启",
                            prop: "acStatus",
                            width: 120,
                            dicData: Dict.ACTIVITY_STATE_ENUM,
                            type: 'select',
                            search: true,
                        }, {
                            label: "活动状态",
                            prop: "acStage",
                            type: 'select',
                            width: 70,
                            dicData: Dict.ACTIVITY_STAGE_ENUM,
                            search: true,
                        },

                    ]
                },
                organizationIdsOption: [],
                goodsClassIdsOptions: [],
                listTree: [],
                goodsClassList: [],
                fourLevel: [],
                goodsClassLevel: []
            };
        },
        computed: {
            ...mapGetters(["permission", 'userInfo']),
            permissionList() {
                return {};
            },
        },
        components: {
            selFile,
            addGoods,
            storeDetail
        },
        mounted() {
            getListTree().then(res => {
                if (res.data.code == 200) {
                    this.newOption.column[4].dicData = res.data.data;
                    this.listTree = res.data.data
                    this.currentAreas = res.data.data
                }
            });
            getOrganizationMapByLevel({level: 4}).then(res => {
                if (res.data.code == 200) {
                    this.fourLevel = res.data.data;
                }
            });
            getMapAllGoodsClass({classLevel: 2}).then(res => {
                if (res.data.code == 200) {
                    this.goodsClassLevel = res.data.data;
                }
            });
            getClassTree().then((res) => {
                if (res.status == 200) {
                    if (res.data.code == 200) {
                        this.goodsClassDict = res.data.data;
                        if (res.data.data.length > 0) {
                            //商品分类
                            let goodsClassIds = this.newOption.column[5].dicData = res.data.data;
                            goodsClassIds.dicData = res.data.data;
                            this.goodsClassList = res.data.data;
                        }
                    } else {
                        this.$message.error(res.data.message);
                    }
                }
            });
        },
        watch: {
            'drawerNew'(e) {
                if (!e) {
                    this.obj.seckillStartTime = []
                    this.obj.seckillEndTime = []
                }
            }
        },
        methods: {
            closeAreas() {
                this.currentGoodsVis = false;
            },
            handleRowClick(row) {
                this.currentAreas.forEach(item => {
                    item.disabled = true; //可选
                    item.childrenNodes.forEach(obj => {
                        obj.disabled = true; //可选
                        obj.childrenNodes.forEach(nodes => {
                            nodes.disabled = true; //可选
                            nodes.childrenNodes.forEach(child => {
                                child.disabled = true; //可选

                            })
                        });
                    });
                });
                if (row.organizationIds.length > 0) {
                    this.currentGoodsName = "活动名称： " + row.acTitle
                    this.defaultKeys = row.organizationIds
                    this.currentGoodsVis = true;
                } else {
                    this.$message({
                        type: "error",
                        message: "该活动未设置区域!"
                    });
                }
            },
            //审核店铺活动
            auditAct(row) {
                this.objAudit = row
                this.auditDialogFormVisible = true
            },
            //审核店铺活动提交
            submitAudit(loading, done) {
                if (this.objAudit.acStatus != 0 && this.objAudit.acStatus != 1) {
                    this.$message.error('请选择审核结果');
                    done();
                    this.onLoad(this.page);
                    return
                }
                this.loading = true;
                platformAuditAct(this.objAudit.id, this.objAudit.acStatus).then((res) => {
                    if (res.data.code == 200) {
                        this.$message.success('审核成功！');
                    } else {
                        this.$message.error(res.data.message);
                    }
                    this.closeDialog()
                    this.loading = true;
                    done();
                    this.onLoad(this.page);
                });

            },
            closeDialog() {
                this.$nextTick(() => {
                    this.$refs["formAudit"].clearValidate();
                    this.$refs["formAudit"].resetForm();
                });
                this.auditDialogFormVisible = false;
            },
            //查看店铺详情
            viewStore(storeId) {
                this.storeId = storeId
                this.dialogFormVisible = true
                this.isView = true
            },
            //关闭店铺详情弹框
            closeDrawers() {
                this.dialogFormVisible = false
            },
            //统计活动
            statisticsBut() {
            },
            // 查看商品详情
            goodsDetail(id) {
                //查看
                this.goodsId = id;
                this.isCheck = true;
                this.dialogTableVisible = true;
            },
            //单个拒绝
            refuse(goodsId) {
                this.goodsloading = true;
                var data = {
                    agIds: goodsId,
                    operateType: -1
                }
                console.log(data)
                joinActivityAudit(data).then((res) => {
                    this.goodsloading = false;
                    this.onGoodsLoad(this.goodsPage);
                    if (res.data.code == 200) {
                        this.$message({
                            type: "success",
                            message: "操作成功!"
                        });
                    } else {
                        this.$message.error(res.data.message);
                    }

                }, error => {
                    console.log(error)
                });
            },
            //单个同意
            pass(goodsId) {
                this.goodsloading = true;
                var data = {
                    agIds: goodsId,
                    operateType: 1
                }
                console.log(data)
                joinActivityAudit(data).then((res) => {
                    this.goodsloading = false;
                    this.onGoodsLoad(this.goodsPage);
                    if (res.data.code == 200) {
                        this.$message({
                            type: "success",
                            message: "操作成功!"
                        });
                    } else {
                        this.$message.error(res.data.message);
                    }
                }, error => {
                    console.log(error)
                });
            },
            //全部拒绝
            refuseAll() {
                if (this.idList.length == 0) {
                    this.$message.success('至少选择一个商品！')
                    return;
                }
                console.log(this.idList)
                this.goodsloading = true;
                var data = {
                    agIds: this.idList,
                    operateType: -1
                }
                console.log(data)
                joinActivityAudit(data).then((res) => {
                    this.$refs.goodsCrud.searchReset()
                    this.goodsloading = false;
                    this.onGoodsLoad(this.goodsPage);
                    if (res.data.code == 200) {
                        this.$message({
                            type: "success",
                            message: "操作成功!"
                        });
                    } else {
                        this.$message.error(res.data.message);
                    }

                }, error => {
                    console.log(error)
                });
            },
            //全部通过
            passAll() {
                if (this.idList.length == 0) {
                    this.$message.success('至少选择一个商品！')
                    return;
                }
                console.log(this.idList)
                this.goodsloading = true;
                var data = {
                    agIds: this.idList,
                    operateType: 1
                }
                console.log(data)
                joinActivityAudit(data).then((res) => {
                    this.$refs.goodsCrud.searchReset()
                    this.goodsloading = false;
                    this.onGoodsLoad(this.goodsPage);
                    if (res.data.code == 200) {
                        this.$message({
                            type: "success",
                            message: "操作成功!"
                        });
                    } else {
                        this.$message.error(res.data.message);
                    }

                }, error => {
                    console.log(error)
                });
            },
            //查看活动链接
            activityLink(row) {
                this.pcLink = row.acPcAccUrl
                this.h5Link = baseUrl + 'pages/activity/SecKil?id=' + row.id
                this.dialogLink = true
            },
            //校验预热时间
            checkPreheatTime(time) {
                this.getTime()
            },
            getTrueArray() {
                console.log(this.obj.acTime);
                if (this.obj.acTime.length > 1) {
                    for (let i = 1; i < this.obj.acTime.length; i++) {
                        let itemData = this.obj.acTime[i - 1];
                        if (!itemData.acTime) {
                            this.obj.acTime.splice(i, 1);
                            this.$message.error('请选择秒杀时间');
                        }
                    }
                }
                console.log(this.obj.acTime);
            },

            getTime() {
                let benginList = []
                if (this.obj.acTime.length > 0) {
                    this.isErrorTime = this.obj.acTime.some((item, index) => {
                        if (item.acTime) {
                            let start = item.acTime[0] + ':00:00'
                            let end = item.acTime[1] + ':00:00'
                            benginList.push(item.acTime[0] + ':00:00')
                            //秒杀开始时间不能小于预热时间
                            console.log(new Date(start).getTime() == new Date(this.obj.preheatTime).getTime())
                            if (this.obj.preheatTime != '' && new Date(start).getTime() < new Date(this.obj.preheatTime).getTime()) {
                                this.$message.error('秒杀开始时间不能小于预热时间');
                                this.timeError = '秒杀开始时间不能小于预热时间'
                                return true;
                            } else if (this.obj.preheatTime != '' && new Date(start).getTime() == new Date(this.obj.preheatTime).getTime()) {
                                this.$message.error('秒杀开始时间不能等于预热时间');
                                this.timeError = '秒杀开始时间不能等于预热时间'
                                return true;
                            } else if (this.obj.preheatTime != '' && new Date(start).getTime() == new Date(end).getTime()) {
                                this.$message.error('秒杀开始时间不能等于秒杀结束时间');
                                this.timeError = '秒杀开始时间不能等于秒杀结束时间'
                                return true;
                            } else {
                                return false;
                            }
                        }
                    })
                }
                if (benginList.length > 0 && !this.isErrorTime) {
                    let set = new Set(benginList);
                    let newArr = Array.from(set);
                    if (newArr.length != benginList.length) {
                        this.$message.error('秒杀开始时间不能重复');
                        this.timeError = '秒杀开始时间不能重复'
                        this.isErrorTime = true
                    }
                }
            },


            //新增或者编辑 确定
            submit(loading, done) {
                this.getTime()
                this.loading = true;
                if (this.isErrorTime) {
                    this.loading = false
                    done();
                    return;
                }
                this.obj.seckillStartTime = []
                this.obj.seckillEndTime = []
                this.obj.acTime.forEach(item => {
                    if (item.acTime) {
                        this.obj.seckillStartTime.push(item.acTime[0] + ':00:00')
                        this.obj.seckillEndTime.push(item.acTime[1] + ':00:00')
                    }
                })
                this.obj.type = 1;
                this.obj.acType = 3;
                let timestamp = (new Date()).getTime();
                let beginTimestamp = new Date(this.obj.seckillEndTime[0]).getTime();
                let endTimestamp = new Date(this.obj.seckillStartTime[0]).getTime();
                let preheatTamp = new Date(this.obj.preheatTime).getTime();
                if (this.obj.acStage != 3 && this.deawerNewTitle != '编辑活动') {
                    if (parseInt(timestamp) > parseInt(beginTimestamp) || parseInt(timestamp) > parseInt(endTimestamp) || parseInt(timestamp) > parseInt(preheatTamp)) {
                        this.onLoad(this.page);
                        done();
                        return this.$message.error("预热时间，活动开始时间，活动结束时间都不能小于当前时间");
                    }
                }
                if (this.obj.seckillEndTime.length != 0 && this.obj.seckillStartTime.length != 0) {
                    saveOrUpdate(this.obj).then(
                        res => {
                            if (res.data.code == 200) {
                                this.$message.success('操作成功!');
                                this.obj.seckillStartTime = [];
                                this.obj.seckillEndTime = [];
                            } else {
                                this.$message.error(res.data.message);
                                return
                            }
                            this.closeDrawer();
                            this.onLoad(this.page);
                            this.loading = false;
                            done();
                        },
                        error => {
                            done();
                            console.log(error);
                        }
                    );
                } else {
                    this.loading = false;
                    done();
                    this.$message.error('秒杀场次至少为一场');
                }
            },
            //新增编辑弹框的取消
            closeDrawer() {
                this.drawerNew = false
                this.isView = false;
                this.$refs.form.resetForm();
                this.$nextTick(() => {
                    this.$refs["form"].clearValidate();

                });
            },
            //查看弹框的取消
            closeShowDrawer() {
                this.drawerShow = false
                this.$refs.showForm.resetForm();
                this.$nextTick(() => {
                    this.$refs["showForm"].clearValidate();
                });
            },
            //打开新增弹框
            addNew() {
                this.deawerNewTitle = '新增活动'
                this.obj.acStatus = 1
                this.obj.acFreeShipping = 0;
                this.newOption.column[2].children.column[0].readonly = false
                this.drawerNew = true
                this.newOption.submitBtn = true;
                this.newOption.column[0].disabled = false;
                this.newOption.column[1].disabled = false;
                this.newOption.column[2].disabled = false;
                this.newOption.column[3].disabled = false;
                this.newOption.column[4].disabled = false;
                this.newOption.column[5].disabled = false;
                this.newOption.column[6].disabled = false;
                this.newOption.column[7].disabled = false;
                this.newOption.column[8].disabled = false;
            },
            //打开编辑弹框
            editAct(row) {
                this.deawerNewTitle = '编辑活动';
                this.obj = row;
                var acTime = [];
                var seckillStartTime = [];
                var seckillEndTime = [];
                row.acSessions.forEach(function (item) {
                    var acTime1 = [];
                    acTime1[0] = item.beginTime.substring(0, 13);
                    acTime1[1] = item.endTime.substring(0, 13);
                    seckillStartTime.push(item.beginTime)
                    seckillEndTime.push(item.endTime)
                    var acTime2 = {};
                    acTime2.acTime = acTime1;
                    acTime.push(acTime2);
                });
                this.obj.acTime = acTime;
                this.obj.seckillStartTime = seckillStartTime
                this.obj.seckillEndTime = seckillEndTime
                this.drawerNew = true;
                this.newOption.submitBtn = true;
                this.newOption.column[0].disabled = false;
                this.newOption.column[1].disabled = false;
                this.newOption.column[2].disabled = true
                this.newOption.column[2].children.column[0].readonly = true;
                this.newOption.column[3].disabled = false;
                this.newOption.column[4].disabled = false;
                this.newOption.column[5].disabled = false;
                this.newOption.column[6].disabled = false;
                this.newOption.column[7].disabled = false;
                this.newOption.column[8].disabled = false;
            },
            //查看
            showAct(row) {
                if (row.type == 1) {
                    this.showOption.column[4].display = false;
                    this.showOption.column[5].display = false;
                } else {
                    this.showOption.column[4].display = true;
                    this.showOption.column[5].display = true;
                }
                this.showObj = row
                this.showObj.acTime = []
                this.showObj.acTime[0] = row.acBeginTime
                this.showObj.acTime[1] = row.acEndTime
                var acTime = [];
                var seckillStartTime = [];
                var seckillEndTime = [];
                row.acSessions.forEach(function (item) {
                    var acTime1 = [];
                    acTime1[0] = item.beginTime.substring(0, 13);
                    acTime1[1] = item.endTime.substring(0, 13);
                    seckillStartTime.push(item.beginTime)
                    seckillEndTime.push(item.endTime)
                    var acTime2 = {};
                    acTime2.acTime = acTime1;
                    acTime.push(acTime2);
                });
                this.showObj.acTime = acTime;
                this.showObj.seckillStartTime = seckillStartTime
                this.showObj.seckillEndTime = seckillEndTime
                let organizationIds = []
                this.listTree.forEach(listT => {
                    listT.childrenNodes.forEach(child => {
                        child.childrenNodes.forEach(nodes => {
                            nodes.childrenNodes.forEach(node => {
                                row.organizationIds.forEach(area => {
                                    if (Number(area) == node.id) {
                                        if (organizationIds.indexOf(nodes.id) > -1) {
                                            organizationIds.push(node.id)
                                        } else if (organizationIds.indexOf(child.id) > -1) {
                                            organizationIds.push(nodes.id)
                                            organizationIds.push(node.id)
                                        } else if (organizationIds.indexOf(listT.id) > -1) {
                                            organizationIds.push(child.id)
                                            organizationIds.push(nodes.id)
                                            organizationIds.push(node.id)
                                        } else {
                                            organizationIds.push(listT.id)
                                            organizationIds.push(child.id)
                                            organizationIds.push(nodes.id)
                                            organizationIds.push(node.id)
                                        }
                                    }
                                })
                            })
                        })
                    })
                })
                if(typeof(row.gcIds)=='string'){
                	row.gcIds= row.gcIds.split(',')
                }
                let gcIds = []
                this.goodsClassList.forEach(listT => {
                    listT.childrenNodes.forEach(child => {
                        child.childrenNodes.forEach(nodes => {
                            row.gcIds.forEach(area => {
                                if (area != '' && area == nodes.id) {
                                    if (gcIds.indexOf(child.id) > -1) {
                                        gcIds.push(nodes.id)
                                    } else if (gcIds.indexOf(listT.id) > -1) {
                                        gcIds.push(child.id)
                                        gcIds.push(nodes.id)
                                    } else {
                                        gcIds.push(listT.id)
                                        gcIds.push(child.id)
                                        gcIds.push(nodes.id)
                                    }
                                }
                            })
                        })
                    })
                })

                this.showObj.organizationIds = []
                if (organizationIds.length > 0) {
                    getOrganizationTreeNodeByIds(organizationIds).then(res => {
                        if (res.data.code == 200) {
                            this.organizationIdsOption = res.data.data;
                        }
                    });
                    organizationIds.forEach(item => {
                        if (this.fourLevel[Number(item)]) {
                            this.showObj.organizationIds.push(this.fourLevel[Number(item)]);
                        }
                    });
                }
                this.showObj.goodsClassIdsName = []
                if (gcIds.length > 0) {
                    getGoodsClassTreeNodesByIds(gcIds).then(res => {
                        if (res.data.code == 200) {
                            this.goodsClassIdsOptions = res.data.data;
                        }
                    });
                    gcIds.forEach(item => {
                        if (this.goodsClassLevel[item]) {
                            this.showObj.goodsClassIdsName.push(this.goodsClassLevel[item]);
                        }
                    });
                }
                this.drawerShow = true;
            },
            //图片返回数据
            selFileCallBack(obj) {
                if (this.imageType == 1) {
                    this.obj.acPcAccUrl = obj[0]
                } else if (this.imageType == 2) {
                    this.obj.acH5AccUrl = obj[0]
                } else if (this.imageType == 3) {
                    this.obj.appPcAccUrl = obj[0]
                }
                console.log(obj)
            },
            //打开选取图片的弹框
            uploadbtn(type) {
                if (!this.isView) {
                    this.imageType = type
                    this.$refs.selFile.open();
                }
            },
            //取消活动
            cancelActivity(id) {
                console.log(id)
                this.loading = true;
                cancel(id).then((res) => {
                    this.loading = false;
                    //如果当前不是第一页并且最后一页剩余一条数据(解决最后一页删除完后还查询最后一页后导致空白的问题)
                    if (this.query.acStage == 3 && this.page.currentPage > 1 && this.page.total % this.page.pageSize == 1) {
                        this.page.currentPage = this.page.currentPage - 1;
                    }
                    this.onLoad(this.page);
                    if (res.data.code == 200) {
                        this.$message({
                            type: "success",
                            message: "操作成功!"
                        });
                    } else {
                        this.$message.error(res.data.message);
                    }

                }, error => {
                    console.log(error)
                });
            },
            //打开申请列表弹框
            applyList(row) {
                console.log(row)
                this.goodsQuery.acId = row.id
                this.onGoodsLoad(this.goodsPage);
                this.drawerActivity = true
            },
            //申请列表时，选择商品的回调
            selectionChange(list) {
                this.idList = []
                list.forEach((item, index) => {
                    this.idList[index] = item.id
                })
            },
            // 申请列表时 商品表格方法
            searchGoodsReset() {
                this.idList = []
                this.$refs.goodsCrud.toggleSelection();
                this.goodsPage.currentPage = 1
                var data = {
                    goodsStatus: 0,
                    acId: this.goodsQuery.acId
                }
                this.goodsQuery = data
                this.onGoodsLoad(this.goodsPage);
            },
            searchGoodsChange(params) {
                this.idList = []
                this.$refs.goodsCrud.toggleSelection();
                this.goodsPage.currentPage = 1
                this.goodsQuery.goodsStatus = 0
                this.goodsQuery.goodsName = params.goodsName
                this.goodsQuery.agStatus = params.agStatus
                this.onGoodsLoad(this.goodsPage, params);
            },

            currentGoodsChange(currentPage) {
                this.goodsPage.currentPage = currentPage;
            },
            sizeGoodsChange(pageSize) {
                this.goodsPage.pageSize = pageSize;
                this.onGoodsLoad(this.goodsPage)
            },
            refreshGoodsChange() {
                this.idList = []
                this.goodsPage.currentPage = 1
                this.$refs.goodsCrud.toggleSelection();
                this.onGoodsLoad(this.goodsPage);
            },
            onGoodsLoad(goodsPage, params = {}) {
                params.goodsStatus = 0;
                getList(
                    goodsPage.currentPage,
                    goodsPage.pageSize,
                    Object.assign(params, this.goodsQuery)
                ).then(res => {
                    this.goodsloading = false;
                    const data = res.data;
                    this.goodsPage.total = data.count;
                    this.goodsList = data.data;
                });
            },

            //清空搜索
            searchReset() {
                this.acTime = ''
                this.query = {
                    acType: 3,
                };
                this.onLoad(this.page);
            },
            searchChange(params) {
                this.page.currentPage = 1
                params.acBeginTime = this.acTime[0]
                params.acEndTime = this.acTime[1]
                params.acType = 3
                console.log(params)
                this.query = params;
                this.onLoad(this.page, params);
            },

            currentChange(currentPage) {
                this.page.currentPage = currentPage;
                this.onLoad(this.page)
            },
            sizeChange(pageSize) {
                this.page.pageSize = pageSize;
                this.onLoad(this.page)
            },
            //刷新
            refreshChange() {
                this.onLoad(this.page);
            },
            onLoad(page, params = {}) {
                this.loading = true;
                if (this.query.organizationIds) {
                    if (this.query.organizationIds.length > 0) {
                        this.query.organizationIds = this.query.organizationIds.toString()
                    } else {
                        params.organizationIds = ''
                    }
                } else {
                    params.organizationIds = ''
                }
                getActList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
                    this.loading = false;
                    const data = res.data;
                    this.page.total = data.count;
                    data.data.forEach(item => {
                        let organizationIds = item.organizationIds.split(',')
                        item.organizationIds = []
                        organizationIds.forEach(ids => {
                            if (ids) {
                                item.organizationIds.push(Number(ids))
                            }

                        })

                    })
                    this.data = data.data;
                });
                if (this.query.organizationIds && this.query.organizationIds.length > 0) {
                    let arr = this.query.organizationIds.split(',')
                    this.query.organizationIds = []
                    arr.forEach(item => {
                        this.query.organizationIds.push(Number(item))
                    })
                }
            }
        }
    };
</script>

<style scoped>
    .drawerHeader {
        font-size: 20px;
        padding: 30px 20px;
    }

    .upload {
        display: flex;
        justify-content: flex-start;
        align-items: center;
    }

    .tsmsg {
        width: 200px;
        font-size: 10px;
        color: #999;
        margin: 0px;
        padding-left: 10px;
    }

    .diaLink {
        font-size: 20px;
        padding: 10px;
    }

    .diaLink p {
        padding: 10px;
    }

    .auditColor {
        color: #010101;
    }
</style>
